﻿using System;
using System.Collections.Generic;
using System.Linq;
using OpenAuth.App.Request;
using OpenAuth.App.Response;
using OpenAuth.App.SSO;
using OpenAuth.Repository.Domain;


namespace OpenAuth.App
{
    public class CustomerApp : BaseApp<Customer>
    {
        public RevelanceManagerApp ReleManagerApp { get; set; }

        /// <summary>
        /// 加载列表
        /// </summary>
        public TableData Load(QueryCustomerListReq request)
        {
             TableData da = new TableData
            {
                count = Repository.GetCount(null),
                data = Repository.Find(request.page, request.limit, "Id desc")
            };
            return da;
        }

        public void Add(Customer obj)
        {
            Repository.Add(obj);
        }

        public  void Delete(string id)
        {
            Repository.Delete2(id);
         //  UnitWork.Delete<Customer>( u => u.Id== id);
        }

        public void Update(Customer obj)
        {
        //    Repository.Update(u => u.Id, obj);
            UnitWork.Update<Customer>(u => u.Id == obj.Id, u => new Customer
            {
                //todo:要修改的字段赋值
                 CustomerCode = obj.CustomerCode,
                 SpellName = obj.SpellName,
                 CustomerName = obj.CustomerName
            });

            //UnitWork.Update<Customer>(u => u.Id == obj.Id, u => new Customer
            //{
            //    //todo:要修改的字段赋值
            //});
        }

    }
}